﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace XMK.Framework.Model
{
    /// <summary>
    /// 返回结果
    /// </summary>
    [Serializable]
    public class ResponseInfo<T>
    {
        #region 属性
        /// <summary>
        /// 返回结果状态[0：为成功，1：为失败]
        /// </summary>
        public int State { get; set; }
        /// <summary>
        /// 返回消息
        /// </summary>
        public string ErrMsg { get; set; }
        /// <summary>
        /// 返回数据
        /// </summary>
        public T Data { get; set; }
        /// <summary>
        /// 分页信息
        /// </summary>
        public PageInfo Page { get; set; }
        /// <summary>
        /// 数据层调用时间
        /// </summary>
        public string DataDifferTime { get; set; }
        #endregion
        #region 构造函数
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ResponseInfo()
        {
            this.State = 0;
        }
        /// <summary>
        /// 带分页信息的构造函数
        /// </summary>
        /// <param name="page"></param>
        public ResponseInfo(PageInfo page) : this()
        {
            this.Page = page;
        }
        /// <summary>
        /// 返回错误信息
        /// </summary>
        /// <param name="errorMessage"></param>
        public ResponseInfo(string errorMessage)
        {
            this.State = 1;
            this.ErrMsg = errorMessage;
        }
        public void Success(string message)
        {
            this.State = 0;
            this.ErrMsg = message;
        }
        public void Failure(string message)
        {
            this.State = 1;
            this.ErrMsg = message;
        }
        #endregion
    }

    /// <summary>
    /// 返回结果
    /// </summary>
    [Serializable]
    public class ResponseInfo:ResponseInfo<object>
    {
        #region 构造函数
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ResponseInfo() : base() { }
        /// <summary>
        /// 带分页信息的构造函数
        /// </summary>
        /// <param name="page"></param>
        public ResponseInfo(PageInfo page) : base(page) { }
        /// <summary>
        /// 返回错误信息
        /// </summary>
        /// <param name="errorMessage"></param>
        public ResponseInfo(string errorMessage) : base(errorMessage) { }
        #endregion
    }
}
